package com.lcredu.utils;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.time.LocalDateTime;

/**
 * @author 黎长容
 * @date 2025-07-04 18:42
 */
public class WebUtils {
    public static String setDir() {
        LocalDateTime now = LocalDateTime.now();
        int year = now.getYear();
        int monthValue = now.getMonthValue();
        int dayOfMonth = now.getDayOfMonth();
        return year + "/" + monthValue + "/" + dayOfMonth;
    }

    public static String fileUpload(HttpServletRequest request) {
        String filePath = "/" + DefaultMsg.DEFAULT_FILEPATH.getFilePath();

        //真正的工作路径
        String fileRealPath = request.getServletContext().getRealPath(filePath);
        String fullPath = fileRealPath + "/" + WebUtils.setDir();
        File file = new File(fileRealPath + "/" + WebUtils.setDir());
        if (!file.exists()) {
            file.mkdirs();
        }
        return fullPath;
    }
}
